home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.compilers / comp.sys.amiga.programmer_10838_000035.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  1.8 KB  |  64 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: dd.chalmers.se!news.chalmers.se!sunic!trane.uninett.no!eunet.no!nuug!EU.net!howland.reston.ans.net!cs.utexas.edu!convex!news.duke.edu!concert!sas!mozart.unx.sas.com!walker
  3. From: walker@twix.unx.sas.com (Doug Walker)
  4. Subject: Re: PROTOTYPING
  5. Originator: walker@twix.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <CpwJE2.9Lz@unx.sas.com>
  8. Date: Mon, 16 May 1994 15:37:13 GMT
  9. References: <2r2sbh$47n@dsm6.dsmnet.com> <2r5hfu$t61@jadzia.CSOS.ORST.EDU>
  10. Nntp-Posting-Host: twix.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Lines: 51
  13.  
  14.  
  15. In article <2r5hfu$t61@jadzia.CSOS.ORST.EDU>, glade@CSOS.ORST.EDU (Glade Diviney) writes:
  16. |> #include <stdio.h>
  17. |> #include <exec/types.h>
  18. |> 
  19. |> void MyPrintfSub(char *format, ULONG args[])
  20. |> {
  21. |>    printf(format,args[1],args[2],args[3],
  22. |>           args[4],args[5],args[6],args[7],args[8]);
  23. |> }
  24. |> 
  25. |> // Passes a pointer to the array of args on to MyPrintfSub().
  26. |> void MyPrintf(char *fmt,...)
  27. |> {
  28. |>     MyPrintfSub (fmt,(ULONG *)&fmt);
  29. |> }
  30. |> 
  31. |> 
  32. |> void main()
  33. |> {
  34. |>     MyPrintf("Testing %d %d %d!\n",1,2,3);
  35. |> }
  36.  
  37. Please do not use this technique.  It assumes you know how the
  38. compiler lays out parameters on the stack, which is NOT a valid
  39. assumption.  Use the ANSI <stdarg.h> includes instead.
  40.  
  41. #include <stdarg.h>
  42. #include <stdio.h>
  43.  
  44. void MyPrintf(char *fmt, ...)
  45. {
  46.    va_list arglist;
  47.    va_start(arglist, fmt);
  48.    vfprintf(stdout, fmt, arglist);
  49.    va_end(arglist);
  50. }
  51.  
  52. void main(void)
  53. {
  54.    MyPrintf("Testing %d %d %d!\n",1,2,3);
  55. }
  56.  
  57. -- 
  58.   *****                    / walker@unx.sas.com
  59.  *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
  60.  *|. o.| ||                \ CompuServe: 71165,2274
  61.   | o  |//     
  62.   ====== 
  63. Any opinions expressed are mine, not those of SAS Institute, Inc.
  64.